//
//  LeftViewController.m
//  UI_Custom
//
//  Created by yutao on 15/2/12.
//  Copyright (c) 2015年 yutao. All rights reserved.
//

#import "LeftViewController.h"

@interface LeftViewController ()

@end

@implementation LeftViewController

#pragma mark 初始化
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.isNight = NO;
    }
    return self;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y + 20, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];

    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
    
}
#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
    return 6;
}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"CellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    
    /*
     * Content in this cell should be inset the size of kMenuOverlayWidth
     */
    
    if (indexPath.row == 0) {
        cell.textLabel.text = @"首页";
        cell.contentView.backgroundColor = [UIColor whiteColor];
        cell.imageView.image = [UIImage imageNamed:@"iconfont-home.png"];
    }
    if (indexPath.row == 1) {
        cell.textLabel.text = @"收藏";
        cell.contentView.backgroundColor = [UIColor whiteColor];
        cell.imageView.image = [UIImage imageNamed:@"shoucang.png"];
        
    }
    if (indexPath.row == 2) {
        cell.textLabel.text = @"清理缓存";
        cell.contentView.backgroundColor = [UIColor whiteColor];
        cell.imageView.image = [UIImage imageNamed:@"shanchu.png"];
        
    }
    if (indexPath.row == 3) {
        cell.textLabel.text = @"下载管理";
        cell.contentView.backgroundColor = [UIColor whiteColor];
        cell.imageView.image = [UIImage imageNamed:@"xiazai.png"];
        
    }
    if (indexPath.row == 4) {
        cell.textLabel.text = @"夜间模式";
        cell.contentView.backgroundColor = [UIColor whiteColor];
        cell.imageView.image = [UIImage imageNamed:@"yejian.png"];
    }
    if (indexPath.row == 5) {
        cell.textLabel.text = @"关于";
        cell.contentView.backgroundColor = [UIColor whiteColor];
        cell.imageView.image = [UIImage imageNamed:@"about.png"];
    }
    
    return cell;
    
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    
    return @"优声轻语";
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UILabel *myLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 120, 40)];
    myLable.text = @"优声轻语";
    myLable.font = [UIFont systemFontOfSize:22];
    UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 56)];
//    [myView setBackgroundColor:[UIColor colorWithRed:120/255.0 green:160/255.0 blue:180/255.0 alpha:1.0]];
    [myView setBackgroundColor:[UIColor whiteColor]];
    [myView addSubview:myLable];
    [myLable release];
    return myView;
}


#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    DDMenuController *menuController = (DDMenuController*)((AppDelegate*)[[UIApplication sharedApplication] delegate]).menuController;
    
    // 设置根视图
    if (indexPath.row == 0) {
        AudioBookViewController *controller = [[AudioBookViewController alloc] init];
        controller.title = [NSString stringWithFormat:@"优声轻语"];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        
        [menuController setRootController:navController animated:YES];
    }
    if (indexPath.row == 1) {
        CollectionViewController *controller = [[CollectionViewController alloc] init];
        controller.title = [NSString stringWithFormat:@"收藏"];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        
        [menuController setRootController:navController animated:YES];
        
    }
    if (indexPath.row == 2) {
        
        UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"提示" message:@"是否确认清除缓存" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [view show];
        [view release];

    }
    if (indexPath.row == 3) {
        
        DownLoadViewController *controller = [[DownLoadViewController alloc] init];
        controller.title = [NSString stringWithFormat:@"下载管理"];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        
        [menuController setRootController:navController animated:YES];
        
    }
    if (indexPath.row == 4) {
        
        self.isNight = !self.isNight;
        
        
        if (self.isNight) {
            NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value",@"key", nil];
            [[NSNotificationCenter defaultCenter]postNotificationName:@"heiyejianglin" object:@"香皂" userInfo: dic];
        }else{
            
            NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value",@"key", nil];
            [[NSNotificationCenter defaultCenter]postNotificationName:@"limingjianglin" object:@"香皂" userInfo: dic];
        }
        
    }
    
    if (indexPath.row == 5) {
        
        AboutViewController *controller = [[AboutViewController alloc] init];
        controller.title = [NSString stringWithFormat:@"关于"];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        
        [menuController setRootController:navController animated:YES];
        
    }
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

// alterView 当点击不同的按钮时实现不通的方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        NSLog(@"不清除");
    }
    if (buttonIndex == 1) {
        NSLog(@"清除数据库");
        
    }
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
